﻿using BusinessResource;
using LightingWebService;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web;
using System.Web.Services;
using System.Xml.Linq;

namespace LightingPlatform.Web
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService
    {
        static WebService()
        {
            string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ServerConfig.xml");
            XDocument doc = XDocument.Load(configPath);
            XElement root = doc.Root;

            ServerConfig.Singleton.Database = root.Element("Database").Value;
            ServerConfig.Singleton.CacheUrl = root.Element("Cache").Value;
            ServerConfig.Singleton.TemplateRoot = root.Element("TemplateRoot").Value;
            ServerConfig.Singleton.ImgRoot = root.Element("ImgRoot").Value;
            ServerConfig.Singleton.ImgUrl = root.Element("ImgUrl").Value;
            ServerConfig.Singleton.ExportRoot = root.Element("ExportRoot").Value;
            ServerConfig.Singleton.ExportUrl = root.Element("ExportUrl").Value;
        }

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public byte[] GetStaticResource()
        {
            LightingFacade service = new LightingFacade();
            return service.GetStaticResource();
        }

        [WebMethod]
        public string SearchProdName()
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdName();
        }

        [WebMethod]
        public byte[] Login(string name, string pwd)
        {
            LightingFacade service = new LightingFacade();
            return service.Login(name, pwd);
        }

        [WebMethod]
        public byte[] SearchProdList(byte[] conditions)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdList(conditions);
        }

        [WebMethod]
        public string SearchProdListToPDF(byte[] conditions)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdListToPDF(conditions);
        }

        [WebMethod]
        public string SearchProdListToExcel(byte[] conditions)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdListToExcel(conditions);
        }

        [WebMethod]
        public byte[] GetUsers()
        {
            LightingFacade service = new LightingFacade();
            return service.GetUsers();
        }

        [WebMethod]
        public int AddUser(byte[] bytes)
        {
            LightingFacade service = new LightingFacade();
            return service.AddUser(bytes);
        }

        [WebMethod]
        public bool UpdateUser(byte[] bytes)
        {
            LightingFacade service = new LightingFacade();
            return service.UpdateUser(bytes);
        }

        [WebMethod]
        public bool DeleteUser(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.DeleteUser(id);
        }

        [WebMethod]
        public int AddProd(byte[] bytes)
        {
            LightingFacade service = new LightingFacade();
            return service.AddProd(bytes);
        }

        [WebMethod]
        public bool UpdateProd(byte[] bytes)
        {
            LightingFacade service = new LightingFacade();
            return service.UpdateProd(bytes);
        }

        [WebMethod]
        public bool DeleteProd(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.DeleteProd(id);
        }

        [WebMethod]
        public byte[] SearchProdClass(byte[] conditions)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdClass(conditions);
        }

        [WebMethod]
        public byte[] SearchProdSeries(byte[] conditions)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdSeries(conditions);
        }

        [WebMethod]
        public string SearchProdSeriesToPDF(byte[] conditions)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdSeriesToPDF(conditions);
        }

        [WebMethod]
        public string SearchProdSeriesToExcel(byte[] conditions)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdSeriesToExcel(conditions);
        }

        [WebMethod]
        public byte[] SearchPrimaryProdInfo(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchPrimaryProdInfo(id);
        }

        [WebMethod]
        public string SearchPrimaryProdInfoToPDF(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchPrimaryProdInfoToPDF(id);
        }

        [WebMethod]
        public string SearchPrimaryProdInfoToExcel(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchPrimaryProdInfoToExcel(id);
        }

        [WebMethod]
        public byte[] SearchProdInfo(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdInfo(id);
        }

        [WebMethod]
        public string SearchProdInfoToPDF(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdInfoToPDF(id);
        }

        [WebMethod]
        public string SearchProdInfoToExcel(int id)
        {
            LightingFacade service = new LightingFacade();
            return service.SearchProdInfoToExcel(id);
        }

        [WebMethod]
        public byte[] SearchRecommendedProd(byte[] conditions)
        {
            return null;
        }
    }
}
